# 从上往下打印出二叉树的每个节点，同层节点从左至右打印。

class TreeNode:
    def __init__(self, x):
        self.val = x
        self.left = None
        self.right = None

class Soluation:
    def print_tree(self,root):
        l = []
        if not root:
            return []
        r = [root]
        while len(r):
            temp = r.pop(0)
            l.append(temp.val)
            if temp.left:
                r.append(temp.left)
            if temp.right:
                r.append(temp.right)
        return l



node1 = TreeNode(1)
node2 = TreeNode(2)
node3 = TreeNode(3)
node4 = TreeNode(4)
node5 = TreeNode(5)
node6 = TreeNode(6)
node7 = TreeNode(7)

node1.left = node2
node1.right = node3
node2.left = node4
node2.right = node5
node3.left = node6
node3.right = node7

s = Soluation()

print(s.print_tree([]))
